package com.york.common;

import com.york.bean.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一全局异常
 * 已有的@RestControllerAdvice是可以用的，当然也可以自己用AOP去写
 */
@RestControllerAdvice
public class ExceptionAdaptController {

    @ExceptionHandler({RuntimeException.class})
    public Result runtimeException(RuntimeException e) {
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler({Exception.class})
    public Result exception(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }
}
